<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>正则验证 | 孙志豪的博客</title><meta name="author" content="孙志豪"><meta name="copyright" content="孙志豪"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1、手机号码的校验12345678910111213const phoneReg &#x3D; &#x2F;^[1][3,4,5,6,7,8,9][0-9]&amp;#123;9&amp;#125;$&#x2F;const phoneStr1 &#x3D; &amp;#x27;18886233487&amp;#x27;console.log(phoneReg.test(phoneStr1)) &#x2F;&#x2F; trueconst phoneStr2 &#x3D; &amp;#x27;172830">
<meta property="og:type" content="article">
<meta property="og:title" content="正则验证">
<meta property="og:url" content="https://szhihao.gitee.io/2022/10/11/15-%E6%AD%A3%E5%88%99%E5%A4%A7%E5%85%A8%E7%AC%94%E8%AE%B0/%E6%AD%A3%E5%88%99%E9%AA%8C%E8%AF%81/index.html">
<meta property="og:site_name" content="孙志豪的博客">
<meta property="og:description" content="1、手机号码的校验12345678910111213const phoneReg &#x3D; &#x2F;^[1][3,4,5,6,7,8,9][0-9]&amp;#123;9&amp;#125;$&#x2F;const phoneStr1 &#x3D; &amp;#x27;18886233487&amp;#x27;console.log(phoneReg.test(phoneStr1)) &#x2F;&#x2F; trueconst phoneStr2 &#x3D; &amp;#x27;172830">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://szhihao.gitee.io/img/%E5%A4%A9%E7%A9%BA.jpeg">
<meta property="article:published_time" content="2022-10-11T12:01:36.000Z">
<meta property="article:modified_time" content="2022-10-16T04:51:07.553Z">
<meta property="article:author" content="孙志豪">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://szhihao.gitee.io/img/%E5%A4%A9%E7%A9%BA.jpeg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://szhihao.gitee.io/2022/10/11/15-%E6%AD%A3%E5%88%99%E5%A4%A7%E5%85%A8%E7%AC%94%E8%AE%B0/%E6%AD%A3%E5%88%99%E9%AA%8C%E8%AF%81/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","languages":{"hits_empty":"We didn't find any results for the search: ${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '正则验证',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-10-16 12:51:07'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="/img/%E5%A4%B4%E5%83%8F.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">44</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">15</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/%E5%A4%A9%E7%A9%BA.jpeg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">孙志豪的博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> Search</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fa fa-graduation-cap"></i><span> 博文</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/categories/"><i class="fa-fw fa fa-archive"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></li><li><a class="site-page child" href="/archives/"><i class="fa-fw fa fa-folder-open"></i><span> 归档</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 生活</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/photos/"><i class="fa-fw fa fa-camera-retro"></i><span> 相册</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 影视</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/links/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comment/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于笔者</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">正则验证</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2022-10-16T04:51:07.553Z" title="Updated 2022-10-16 12:51:07">2022-10-16</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%AD%A3%E5%88%99%E5%A4%A7%E5%85%A8%E7%AC%94%E8%AE%B0/">正则大全笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="正则验证"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><hr>
<h2 id="1、手机号码的校验"><a href="#1、手机号码的校验" class="headerlink" title="1、手机号码的校验"></a>1、手机号码的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> phoneReg = <span class="regexp">/^[1][3,4,5,6,7,8,9][0-9]&#123;9&#125;$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> phoneStr1 = <span class="string">&#x27;18886233487&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(phoneReg.<span class="title function_">test</span>(phoneStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> phoneStr2 = <span class="string">&#x27;17283017203897&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(phoneReg.<span class="title function_">test</span>(phoneStr2)) <span class="comment">// false</span></span><br><span class="line"><span class="keyword">if</span> (phoneReg.<span class="title function_">test</span>(phone.<span class="property">value</span>)) &#123;</span><br><span class="line">        reg.<span class="property">value</span> = <span class="number">1</span>;</span><br><span class="line">   &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        reg.<span class="property">value</span> = <span class="number">2</span>;</span><br><span class="line">   &#125;</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(reg.<span class="property">value</span>);</span><br></pre></td></tr></table></figure>

<h2 id="2、身份证的校验"><a href="#2、身份证的校验" class="headerlink" title="2、身份证的校验"></a>2、身份证的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> sfzReg = <span class="regexp">/^[1-9]\d&#123;5&#125;(18|19|([23]\d))\d&#123;2&#125;((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d&#123;3&#125;[0-9Xx]$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> sfzStr1 = <span class="string">&#x27;415106199801012130&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(sfzReg.<span class="title function_">test</span>(sfzStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> sfzStr2 = <span class="string">&#x27;718381298381212183&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(sfzReg.<span class="title function_">test</span>(sfzStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="3、邮箱的校验"><a href="#3、邮箱的校验" class="headerlink" title="3、邮箱的校验"></a>3、邮箱的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> emailReg = <span class="regexp">/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]&#123;2,4&#125;)$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> emailStrWY = <span class="string">&#x27;956666@163.com&#x27;</span> <span class="comment">// 163邮箱</span></span><br><span class="line"><span class="keyword">const</span> emailStrQQ = <span class="string">&#x27;956666@qq.com&#x27;</span> <span class="comment">// qq邮箱</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(emailReg.<span class="title function_">test</span>(emailStrWY)) <span class="comment">// true</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(emailReg.<span class="title function_">test</span>(emailStrQQ)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> noEmail = <span class="string">&#x27;72873213.com&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(emailReg.<span class="title function_">test</span>(noEmail)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="4、URL的校验"><a href="#4、URL的校验" class="headerlink" title="4、URL的校验"></a>4、URL的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> urlReg = <span class="regexp">/^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]&#123;2,6&#125;)([\/\w \.-]*)*\/?$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> urlStr1 = <span class="string">&#x27;https://haha.sunshine.com/xxx/xxx&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(urlReg.<span class="title function_">test</span>(urlStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> urlStr2 = <span class="string">&#x27;sss://haha.sunshine.com/xxx/xxx&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(urlReg.<span class="title function_">test</span>(urlStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="5、IPv4的校验"><a href="#5、IPv4的校验" class="headerlink" title="5、IPv4的校验"></a>5、IPv4的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> ipv4Reg = <span class="regexp">/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)&#123;3&#125;(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> ipv4Str1 = <span class="string">&#x27;122.12.56.65&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(ipv4Reg.<span class="title function_">test</span>(ipv4Str1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> ipv4Str2 = <span class="string">&#x27;122.12.56.655&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(ipv4Reg.<span class="title function_">test</span>(ipv4Str2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="6、16进制颜色的校验"><a href="#6、16进制颜色的校验" class="headerlink" title="6、16进制颜色的校验"></a>6、16进制颜色的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> color16Reg = <span class="regexp">/^#?([a-fA-F0-9]&#123;6&#125;|[a-fA-F0-9]&#123;3&#125;)$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> color16Str1 = <span class="string">&#x27;#fff&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(color16Reg.<span class="title function_">test</span>(color16Str1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> color16Str2 = <span class="string">&#x27;#1234567&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(color16Reg.<span class="title function_">test</span>(color16Str2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="7、日期-YYYY-MM-DD"><a href="#7、日期-YYYY-MM-DD" class="headerlink" title="7、日期 YYYY-MM-DD"></a>7、日期 YYYY-MM-DD</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> dateReg = <span class="regexp">/^\d&#123;4&#125;(\-)\d&#123;1,2&#125;\1\d&#123;1,2&#125;$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> dateStr1 = <span class="string">&#x27;2021-10-10&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(dateReg.<span class="title function_">test</span>(dateStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> dateStr2 = <span class="string">&#x27;2021-01-01 1&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(dateReg.<span class="title function_">test</span>(dateStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="8、日期-YYYY-MM-DD-hh-mm-ss"><a href="#8、日期-YYYY-MM-DD-hh-mm-ss" class="headerlink" title="8、日期 YYYY-MM-DD hh:mm:ss"></a>8、日期 YYYY-MM-DD hh:mm:ss</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> dateReg = <span class="regexp">/^(\d&#123;1,4&#125;)(-|\/)(\d&#123;1,2&#125;)\2(\d&#123;1,2&#125;) (\d&#123;1,2&#125;):(\d&#123;1,2&#125;):(\d&#123;1,2&#125;)$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> dateStr1 = <span class="string">&#x27;2021-10-10 16:16:16&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(dateReg.<span class="title function_">test</span>(dateStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> dateStr2 = <span class="string">&#x27;2021-10-10 16:&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(dateReg.<span class="title function_">test</span>(dateStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="9、整数的校验"><a href="#9、整数的校验" class="headerlink" title="9、整数的校验"></a>9、整数的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> intReg = <span class="regexp">/^[-+]?\d*$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> intNum1 = <span class="number">12345</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(intReg.<span class="title function_">test</span>(intNum1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> intNum2 = <span class="number">12345.1</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(intReg.<span class="title function_">test</span>(intNum2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="10、小数的校验"><a href="#10、小数的校验" class="headerlink" title="10、小数的校验"></a>10、小数的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> floatReg = <span class="regexp">/^[-\+]?\d+(\.\d+)?$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> floatNum = <span class="number">1234.5</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(floatReg.<span class="title function_">test</span>(floatNum)) <span class="comment">// true</span></span><br></pre></td></tr></table></figure>

<h2 id="11、保留n位小数"><a href="#11、保留n位小数" class="headerlink" title="11、保留n位小数"></a>11、保留n位小数</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">checkFloat</span>(<span class="params">n</span>) &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">RegExp</span>(<span class="string">`^([1-9]+[\d]*(.[0-9]&#123;1,<span class="subst">$&#123;n&#125;</span>&#125;)?)$`</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 保留2位小数</span></span><br><span class="line"><span class="keyword">const</span> floatReg = <span class="title function_">checkFloat</span>(<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> floatNum1 = <span class="number">1234.5</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(floatReg.<span class="title function_">test</span>(floatNum1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> floatNum2 = <span class="number">1234.55</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(floatReg.<span class="title function_">test</span>(floatNum2)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> floatNum3 = <span class="number">1234.555</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(floatReg.<span class="title function_">test</span>(floatNum3)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="12、邮政编号的校验"><a href="#12、邮政编号的校验" class="headerlink" title="12、邮政编号的校验"></a>12、邮政编号的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> postalNoReg = <span class="regexp">/^\d&#123;6&#125;$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> postalNoStr1 = <span class="string">&#x27;522000&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(postalNoReg.<span class="title function_">test</span>(postalNoStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> postalNoStr2 = <span class="string">&#x27;5220000&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(postalNoReg.<span class="title function_">test</span>(postalNoStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="13、QQ号的校验"><a href="#13、QQ号的校验" class="headerlink" title="13、QQ号的校验"></a>13、QQ号的校验</h2><p>说明：5-11位数字</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> qqReg = <span class="regexp">/^[1-9][0-9]&#123;4,10&#125;$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> qqStr1 = <span class="string">&#x27;1915801633&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(qqReg.<span class="title function_">test</span>(qqStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> qqStr2 = <span class="string">&#x27;191580163333&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(qqReg.<span class="title function_">test</span>(qqStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="14、微信号的校验"><a href="#14、微信号的校验" class="headerlink" title="14、微信号的校验"></a>14、微信号的校验</h2><p>说明：6至20位，以字母开头，字母，数字，减号，下划线</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> wxReg = <span class="regexp">/^[a-zA-Z]([-_a-zA-Z0-9]&#123;5,19&#125;)+$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> wxStr1 = <span class="string">&#x27;linsanxin885577&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(wxReg.<span class="title function_">test</span>(wxStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> wxStr2 = <span class="string">&#x27;厉害了我的vx&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(wxReg.<span class="title function_">test</span>(wxStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="15、车牌号的校验"><a href="#15、车牌号的校验" class="headerlink" title="15、车牌号的校验"></a>15、车牌号的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> carNoReg = <span class="regexp">/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]&#123;1&#125;[A-Z]&#123;1&#125;[A-Z0-9]&#123;4&#125;[A-Z0-9挂学警港澳]&#123;1&#125;$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> carNoStr1 = <span class="string">&#x27;粤A12345&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(carNoReg.<span class="title function_">test</span>(carNoStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> carNoStr2 = <span class="string">&#x27;广东A12345&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(carNoReg.<span class="title function_">test</span>(carNoStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="16、只含字母的字符串"><a href="#16、只含字母的字符串" class="headerlink" title="16、只含字母的字符串"></a>16、只含字母的字符串</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> letterReg = <span class="regexp">/^[a-zA-Z]+$/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> letterStr1 = <span class="string">&#x27;sunshineLin&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(letterReg.<span class="title function_">test</span>(letterStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> letterStr2 = <span class="string">&#x27;sunshine_Lin&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(letterReg.<span class="title function_">test</span>(letterStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="17、包含中文的字符串"><a href="#17、包含中文的字符串" class="headerlink" title="17、包含中文的字符串"></a>17、包含中文的字符串</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> cnReg = <span class="regexp">/[\u4E00-\u9FA5]/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> cnStr1 = <span class="string">&#x27;我是sunshine_Lin，林三心&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(cnReg.<span class="title function_">test</span>(cnStr1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> cnStr2 = <span class="string">&#x27;sunshine_Lin&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(cnReg.<span class="title function_">test</span>(cnStr2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="18、密码强度的校验"><a href="#18、密码强度的校验" class="headerlink" title="18、密码强度的校验"></a>18、密码强度的校验</h2><p>说明：密码中必须包含字母、数字、特称字符，至少8个字符，最多30个字符</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> passwordReg = <span class="regexp">/(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).&#123;8,30&#125;/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> password1 = <span class="string">&#x27;sunshine_Lin12345..&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(passwordReg.<span class="title function_">test</span>(password1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> password2 = <span class="string">&#x27;sunshineLin12345&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(passwordReg.<span class="title function_">test</span>(password2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="19、字符串长度n的校验"><a href="#19、字符串长度n的校验" class="headerlink" title="19、字符串长度n的校验"></a>19、字符串长度n的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">checkStrLength</span>(<span class="params">n</span>) &#123;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">RegExp</span>(<span class="string">`^.&#123;<span class="subst">$&#123;n&#125;</span>&#125;$`</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 校验长度为3的字符串</span></span><br><span class="line"><span class="keyword">const</span> lengthReg = <span class="title function_">checkStrLength</span>(<span class="number">3</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> str1 = <span class="string">&#x27;hhh&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(lengthReg.<span class="title function_">test</span>(str1)) <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> str2 = <span class="string">&#x27;hhhhh&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(lengthReg.<span class="title function_">test</span>(str2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="20、文件拓展名的校验"><a href="#20、文件拓展名的校验" class="headerlink" title="20、文件拓展名的校验"></a>20、文件拓展名的校验</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">checkFileName</span> (arr) &#123;</span><br><span class="line">  arr = arr.<span class="title function_">map</span>(<span class="function"><span class="params">name</span> =&gt;</span> <span class="string">`.<span class="subst">$&#123;name&#125;</span>`</span>).<span class="title function_">join</span>(<span class="string">&#x27;|&#x27;</span>)</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">RegExp</span>(<span class="string">`(<span class="subst">$&#123;arr&#125;</span>)$`</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> filenameReg = <span class="title function_">checkFileName</span>([<span class="string">&#x27;jpg&#x27;</span>, <span class="string">&#x27;png&#x27;</span>, <span class="string">&#x27;txt&#x27;</span>])</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> filename1 = <span class="string">&#x27;sunshine.jpg&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(filenameReg.<span class="title function_">test</span>(filename1)) <span class="comment">// true</span></span><br><span class="line"><span class="keyword">const</span> filename2 = <span class="string">&#x27;sunshine.png&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(filenameReg.<span class="title function_">test</span>(filename2)) <span class="comment">// true</span></span><br><span class="line"><span class="keyword">const</span> filename3 = <span class="string">&#x27;sunshine.txt&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(filenameReg.<span class="title function_">test</span>(filename3)) <span class="comment">// true</span></span><br><span class="line"><span class="keyword">const</span> filename4 = <span class="string">&#x27;sunshine.md&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(filenameReg.<span class="title function_">test</span>(filename4)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<h2 id="21、匹配img和src"><a href="#21、匹配img和src" class="headerlink" title="21、匹配img和src"></a>21、匹配img和src</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> imgReg = <span class="regexp">/&lt;img.*?src=[\&quot;|\&#x27;]?(.*?)[\&quot;|\&#x27;]?\s.*?&gt;/ig</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> htmlStr = <span class="string">&#x27;&lt;div&gt;&lt;/div&gt;&lt;img src=&quot;sunshine.png&quot; /&gt;&lt;img src=&quot;sunshine111.png&quot; /&gt;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(imgReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;&lt;img src=&quot;sunshine.png&quot; /&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;sunshine.png&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 11,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;div&gt;&lt;/div&gt;&lt;img src=&quot;sunshine.png&quot; /&gt;&lt;img src=&quot;sunshine111.png&quot; /&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(imgReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;&lt;img src=&quot;sunshine111.png&quot; /&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;sunshine111.png&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 37,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;div&gt;&lt;/div&gt;&lt;img src=&quot;sunshine.png&quot; /&gt;&lt;img src=&quot;sunshine111.png&quot; /&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ] </span></span><br></pre></td></tr></table></figure>

<h2 id="22、匹配html中的注释"><a href="#22、匹配html中的注释" class="headerlink" title="22、匹配html中的注释"></a>22、匹配html中的注释</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> noteReg = <span class="regexp">/&lt;!--(.*?)--&gt;/g</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> htmlStr = <span class="string">&#x27;&lt;!--一个div标签--&gt; &lt;div&gt;&lt;/div&gt; &lt;!--一个div标签--&gt; &lt;div&gt;&lt;/div&gt;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(noteReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;&lt;!--一个div标签--&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;一个div标签&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 0,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;!--一个div标签--&gt; &lt;div&gt;&lt;/div&gt; &lt;!--一个div标签--&gt; &lt;div&gt;&lt;/div&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(noteReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;&lt;!--一个div标签--&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;一个div标签&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 27,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;!--一个div标签--&gt; &lt;div&gt;&lt;/div&gt; &lt;!--一个div标签--&gt; &lt;div&gt;&lt;/div&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br></pre></td></tr></table></figure>

<h2 id="23、匹配html中的style"><a href="#23、匹配html中的style" class="headerlink" title="23、匹配html中的style"></a>23、匹配html中的style</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> styleReg = <span class="regexp">/style=&quot;[^=&gt;]*&quot;([(\s+\w+=)|&gt;])/g</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> htmlStr = <span class="string">&#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(styleReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;style=&quot;background:#000;&quot;&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 5,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(styleReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;style=&quot;color:#fff&quot;&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 36,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br></pre></td></tr></table></figure>

<h2 id="24、匹配html中的颜色"><a href="#24、匹配html中的颜色" class="headerlink" title="24、匹配html中的颜色"></a>24、匹配html中的颜色</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> colorReg = <span class="regexp">/#([A-Fa-f0-9]&#123;6&#125;|[A-Fa-f0-9]&#123;3&#125;)/g</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> htmlStr = <span class="string">&#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(colorReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;#000&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;000&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 23,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(colorReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="comment">// [</span></span><br><span class="line"><span class="comment">//   &#x27;#fff&#x27;,</span></span><br><span class="line"><span class="comment">//   &#x27;fff&#x27;,</span></span><br><span class="line"><span class="comment">//   index: 49,</span></span><br><span class="line"><span class="comment">//   input: &#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&#x27;,</span></span><br><span class="line"><span class="comment">//   groups: undefined</span></span><br><span class="line"><span class="comment">// ]</span></span><br></pre></td></tr></table></figure>

<h2 id="25、匹配htmlTag（html标签）"><a href="#25、匹配htmlTag（html标签）" class="headerlink" title="25、匹配htmlTag（html标签）"></a>25、匹配htmlTag（html标签）</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> endReg = <span class="regexp">/&lt;(&quot;[^&quot;]*&quot;|&#x27;[^&#x27;]*&#x27;|[^&#x27;&quot;&gt;])*&gt;/g</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> htmlStr = <span class="string">&#x27;&lt;div style=&quot;background:#000;&quot;&gt;&lt;span style=&quot;color:#fff&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;h1&gt;&lt;/h1&gt;&#x27;</span></span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(endReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(endReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(endReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(endReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(endReg.<span class="title function_">exec</span>(htmlStr))</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(endReg.<span class="title function_">exec</span>(htmlStr))</span><br></pre></td></tr></table></figure>

<h2 id="26、名字"><a href="#26、名字" class="headerlink" title="26、名字"></a>26、名字</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">my$(&quot;name&quot;).addEventListener(&quot;blur&quot;,function()&#123;</span><br><span class="line">			if(/^[\u4e00-\u9fa5]&#123;2,6&#125;$/.test(this.value))</span><br><span class="line">			&#123;</span><br><span class="line">			this.style.backgroundColor=&quot;green&quot;;</span><br><span class="line">			</span><br><span class="line">			&#125;</span><br><span class="line">			else</span><br><span class="line">			&#123;</span><br><span class="line">			this.style.backgroundColor=&quot;red&quot;;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;);</span><br></pre></td></tr></table></figure>

<hr>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="https://szhihao.gitee.io">孙志豪</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://szhihao.gitee.io/2022/10/11/15-%E6%AD%A3%E5%88%99%E5%A4%A7%E5%85%A8%E7%AC%94%E8%AE%B0/%E6%AD%A3%E5%88%99%E9%AA%8C%E8%AF%81/">https://szhihao.gitee.io/2022/10/11/15-%E6%AD%A3%E5%88%99%E5%A4%A7%E5%85%A8%E7%AC%94%E8%AE%B0/%E6%AD%A3%E5%88%99%E9%AA%8C%E8%AF%81/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="/img/%E5%A4%A9%E7%A9%BA.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2022/10/11/13-%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91%E8%B7%AF%E7%BA%BF/%E5%89%8D%E7%AB%AF%E5%BC%80%E5%8F%91%E8%B7%AF%E7%BA%BF/"><img class="prev-cover" src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">前端开发路线</div></div></a></div><div class="next-post pull-right"><a href="/2022/10/11/15-%E6%AD%A3%E5%88%99%E5%A4%A7%E5%85%A8%E7%AC%94%E8%AE%B0/%E7%9F%A5%E9%81%93%E8%BF%99%2020%20%E4%B8%AA%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%8C%E8%83%BD%E8%AE%A9%E4%BD%A0%E5%B0%91%E5%86%99%201,000%20%E8%A1%8C%E4%BB%A3%E7%A0%81/"><img class="next-cover" src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">20 个正则表达式，能让你少写 1,000 行代</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="/img/%E5%A4%B4%E5%83%8F.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">孙志豪</div><div class="author-info__description">吾日三省吾身：为人谋而不忠乎？与朋友交而不信乎？传不习乎？</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">44</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">15</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/szhihao/szhihao"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/szhihao/szhihao" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/qq_54753561" target="_blank" title="CSDN"><i class="fa fa-book-open"></i></a><a class="social-icon" href="mailto:zhihaomail@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%E3%80%81%E6%89%8B%E6%9C%BA%E5%8F%B7%E7%A0%81%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">1.</span> <span class="toc-text">1、手机号码的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%E3%80%81%E8%BA%AB%E4%BB%BD%E8%AF%81%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">2.</span> <span class="toc-text">2、身份证的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%E3%80%81%E9%82%AE%E7%AE%B1%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">3.</span> <span class="toc-text">3、邮箱的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%E3%80%81URL%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">4.</span> <span class="toc-text">4、URL的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5%E3%80%81IPv4%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">5.</span> <span class="toc-text">5、IPv4的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6%E3%80%8116%E8%BF%9B%E5%88%B6%E9%A2%9C%E8%89%B2%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">6.</span> <span class="toc-text">6、16进制颜色的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7%E3%80%81%E6%97%A5%E6%9C%9F-YYYY-MM-DD"><span class="toc-number">7.</span> <span class="toc-text">7、日期 YYYY-MM-DD</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8%E3%80%81%E6%97%A5%E6%9C%9F-YYYY-MM-DD-hh-mm-ss"><span class="toc-number">8.</span> <span class="toc-text">8、日期 YYYY-MM-DD hh:mm:ss</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9%E3%80%81%E6%95%B4%E6%95%B0%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">9.</span> <span class="toc-text">9、整数的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10%E3%80%81%E5%B0%8F%E6%95%B0%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">10.</span> <span class="toc-text">10、小数的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11%E3%80%81%E4%BF%9D%E7%95%99n%E4%BD%8D%E5%B0%8F%E6%95%B0"><span class="toc-number">11.</span> <span class="toc-text">11、保留n位小数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12%E3%80%81%E9%82%AE%E6%94%BF%E7%BC%96%E5%8F%B7%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">12.</span> <span class="toc-text">12、邮政编号的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13%E3%80%81QQ%E5%8F%B7%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">13.</span> <span class="toc-text">13、QQ号的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14%E3%80%81%E5%BE%AE%E4%BF%A1%E5%8F%B7%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">14.</span> <span class="toc-text">14、微信号的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#15%E3%80%81%E8%BD%A6%E7%89%8C%E5%8F%B7%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">15.</span> <span class="toc-text">15、车牌号的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#16%E3%80%81%E5%8F%AA%E5%90%AB%E5%AD%97%E6%AF%8D%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">16.</span> <span class="toc-text">16、只含字母的字符串</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#17%E3%80%81%E5%8C%85%E5%90%AB%E4%B8%AD%E6%96%87%E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">17.</span> <span class="toc-text">17、包含中文的字符串</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#18%E3%80%81%E5%AF%86%E7%A0%81%E5%BC%BA%E5%BA%A6%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">18.</span> <span class="toc-text">18、密码强度的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#19%E3%80%81%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%95%BF%E5%BA%A6n%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">19.</span> <span class="toc-text">19、字符串长度n的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#20%E3%80%81%E6%96%87%E4%BB%B6%E6%8B%93%E5%B1%95%E5%90%8D%E7%9A%84%E6%A0%A1%E9%AA%8C"><span class="toc-number">20.</span> <span class="toc-text">20、文件拓展名的校验</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#21%E3%80%81%E5%8C%B9%E9%85%8Dimg%E5%92%8Csrc"><span class="toc-number">21.</span> <span class="toc-text">21、匹配img和src</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#22%E3%80%81%E5%8C%B9%E9%85%8Dhtml%E4%B8%AD%E7%9A%84%E6%B3%A8%E9%87%8A"><span class="toc-number">22.</span> <span class="toc-text">22、匹配html中的注释</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#23%E3%80%81%E5%8C%B9%E9%85%8Dhtml%E4%B8%AD%E7%9A%84style"><span class="toc-number">23.</span> <span class="toc-text">23、匹配html中的style</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#24%E3%80%81%E5%8C%B9%E9%85%8Dhtml%E4%B8%AD%E7%9A%84%E9%A2%9C%E8%89%B2"><span class="toc-number">24.</span> <span class="toc-text">24、匹配html中的颜色</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#25%E3%80%81%E5%8C%B9%E9%85%8DhtmlTag%EF%BC%88html%E6%A0%87%E7%AD%BE%EF%BC%89"><span class="toc-number">25.</span> <span class="toc-text">25、匹配htmlTag（html标签）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#26%E3%80%81%E5%90%8D%E5%AD%97"><span class="toc-number">26.</span> <span class="toc-text">26、名字</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/10/12/04-%E5%89%8D%E7%AB%AF%EF%BC%88%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87%EF%BC%89/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87/" title="性能优化面试题"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="性能优化面试题"/></a><div class="content"><a class="title" href="/2022/10/12/04-%E5%89%8D%E7%AB%AF%EF%BC%88%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87%EF%BC%89/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96%E7%AF%87/" title="性能优化面试题">性能优化面试题</a><time datetime="2022-10-12T12:01:36.000Z" title="Created 2022-10-12 20:01:36">2022-10-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS字符串方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS字符串方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS字符串方法">JS字符串方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS对象方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS对象方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E8%AE%B0%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS对象方法">JS对象方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS数组方法"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS数组方法"/></a><div class="content"><a class="title" href="/2022/10/11/05-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%96%B9%E6%B3%95%E5%AE%B6%E8%A7%84%EF%BC%89/JS%E6%95%B0%E7%BB%84%E6%96%B9%E6%B3%95%E2%80%94%E2%80%94%E9%80%9F%E6%9F%A5%E5%B0%8F%E6%9C%AC%E5%AD%90/" title="JS数组方法">JS数组方法</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/" title="开发封装函数"><img src= "" data-lazy-src="/img/%E5%A4%A9%E7%A9%BA.jpeg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="开发封装函数"/></a><div class="content"><a class="title" href="/2022/10/11/07-%E6%A0%B8%E5%BF%83js%EF%BC%88%E6%89%8B%E5%86%99%E7%AF%87%EF%BC%89/%E5%BC%80%E5%8F%91%E5%B0%81%E8%A3%85%E5%87%BD%E6%95%B0/" title="开发封装函数">开发封装函数</a><time datetime="2022-10-11T12:01:36.000Z" title="Created 2022-10-11 20:01:36">2022-10-11</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 孙志豪</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">Search</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  Loading the Database</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="Search for Posts" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>